package com.zhia.demo.controller;

import com.zhia.demo.entity.BrowseHistoryEntity;
import com.zhia.demo.service.BrowseHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.util.StringUtils;

/**
 * @author DONG
 * @create 2023/11/5 16:00
 */
@RestController
public class BrowseHistoryController {
    @Autowired
    private BrowseHistoryService browseHistoryService;
    @PostMapping("/browseHistory/{bookId}/{chapter}")
    public void save(@PathVariable("bookId") String bookId,@PathVariable("chapter") String chapter,@CookieValue(name = "USERSESSION", defaultValue = "") String cookie) {
        if(!StringUtils.isEmpty(cookie)) {
            if(!StringUtils.isEmpty(chapter)) {
                browseHistoryService.saveHistory(bookId,Integer.parseInt(cookie),Integer.parseInt(chapter));
            }
        }
    }
}
